# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Anders Bergh <anders1@gmail.com>

pkgbase=luasocket
pkgname=(lua-socket lua51-socket lua52-socket lua53-socket)
pkgver=3.1.0
pkgrel=1
_rockrel=1
epoch=1
pkgdesc='Networking support library for the Lua language'
arch=(loong64 x86_64)
url="https://github.com/lunarmodules/$pkgbase"
license=(MIT)
options=(debug)
makedepends=(lua
             lua51
             lua52
             lua53
             luarocks)
_archive="$pkgbase-$pkgver"
_rock="$_archive-$_rockrel.linux-`uname -m`.rock"
source=("$url/archive/v$pkgver/$_archive.tar.gz")
sha256sums=('bf033aeb9e62bcaa8d007df68c119c966418e8c9ef7e4f2d7e96bddeca9cca6e')

build() {
	cd "$_archive"
	for LUAVER in 5.1 5.2 5.3 5.4; do
		luarocks --lua-version "$LUAVER" \
			make --pack-binary-rock --deps-mode none -- "rockspecs/$_archive-$_rockrel.rockspec"
		install -Dm0644 -t "lua$LUAVER/" "$_rock"
	done
}

_package() {
	cd "$_archive"
	depends=("${pkgname%-*}")
	luarocks --lua-version "$1" --tree "$pkgdir/usr/" \
		install --deps-mode none --no-manifest -- "lua$1/$_rock"
	install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgname/" LICENSE
}

package_lua-socket() {
	_package 5.4
}

package_lua53-socket() {
	_package 5.3
}

package_lua52-socket() {
	_package 5.2
}

package_lua51-socket() {
	replaces=(luasocket)
	conflicts=(luasocket)
	_package 5.1
}
